package org.swift.mashup.engine.model;

import java.io.IOException;
import java.io.OutputStream;

public class ByteArrayActivityContext implements ActivityContext {

	private byte[] value;
	
	private boolean wasString;
	
	public ByteArrayActivityContext(String value) {
		this.wasString = true;
		this.value = value.getBytes();
	}
	
	public ByteArrayActivityContext(byte[] value) {
		this.wasString = false;
		this.value = value;
	}
	
	@Override
	public byte[] getBytes() throws IOException {
		return value;
	}

	@Override
	public long getSize() {
		return value.length;
	}

	@Override
	public void writeAll(OutputStream outputStream) throws IOException {
		outputStream.write(this.value);		
	}

	@Override
	public Object getValue() {
		if (wasString) {
			return new String(this.value);
		} else {
			return value;
		}
	}

}
